/**
 * LSA.java
 *
 * @author Philip Kwok
 */


package SSF.OS.OSPF;


import java.util.Vector;


// ========================== class SSF.OS.OSPF.LSA ======================== //
/**
 * An OSPF Link State Advertisement packet.  It extends an OSPF packet. The
 * following table shows the information that goes into the different fields
 * depending on the LSA packet type:
 *
 * <pre><code>
 * <font face="Courier, Courier New">
 * <br>TYPE                       LS Identification    Sent by          Received by
 * <br>--------------------------------------------------------------------------------------
 * <br>1 - Router link            OSPF Router ID       each router      rtrs in the same area
 * <br>2 - Network link           IP itrf address of
 * <br>                           network's dest. router
 * <br>3 - Summary link (IP net)  IP network number    Area border rtr  rtrs in the same area
 * <br>4 - Summary link (ASBR)    ASBR OSPF rtr ID     ASB rtr          rtrs in the AS
 * <br>5 - External link          IP network number    AS boundary rtr  rtrs in the AS
 * <br>--------------------------------------------------------------------------------------
 *
 * <p>In RFC 2178, but NOT implemented:
 *
 * <p>1) LS checksum
 * <br>2) length
 * <br>3) Options
 * </code></pre>
 */
public class LSA extends ProtocolMessage {

  // ......................... constants ........................... //

  /** Indicates a router-LSA. */
  public static final int ROUTER_LSA          = 1;
  /** Indicates a network-LSA. */
  public static final int NETWORK_LSA         = 2;
  /** Indicates a summary-LSA (IP network). */
  public static final int SUMMARY_NETWORK_LSA = 3;
  /** Indicates a summary-LSA (ASBR). */
  public static final int SUMMARY_ASBR_LSA    = 4;
  /** Indicates an AS External LSA. */
  public static final int AS_EXTERNAL_LSA     = 5;

  // ........................ member data .......................... //

  /** The link state sequence number of this LSA header. */
  public int seqnum = 0;

  /** The age of this Link State Advertisement. */
  public int age = 0;

  /** The type of this Link State Advertisement. */
  public byte typ;

  /** The Link State Identification of this LSA. */
  public int id;

  /** The advertising router of this LSA. */
  public int adrtr;
  public String adrtrnh;

  /** The contents of this LSA packet: a list of link information. */
  public Vector contents;


  // --------------------------- constructor LSA --------------------------- //
  /**
   * Constructs a Link State Advertisement.
   *
   * @param seq   LSA sequence number.
   * @param t     LSA type.
   * @param lsID  Link state ID (OSPF router ID).
   * @param ar    The ID of the advertising router.
   * @param arnh  The NHI prefix address of the advertising router.
   * @param cont  The LSA list to send.
   */
  public LSA(int seq, int t, int lsID, int ar, String arnh, Vector con) {
    seqnum = seq;
    typ = (byte)t;
    id = lsID;
    adrtr = ar;
    adrtrnh = arnh;
    contents = con;
  }

  // ----------------------------- LSA.toString ---------------------------- //
  public String toString() {
    String s = "";
    s = seqnum + " " + typ + " " + IP_s.IPtoString(id) + " " +
        IP_s.IPtoString(adrtr) + " " + adrtrnh + " " + age;
    return s;
  }

} // end class LSA
